﻿using Core.Dtos;
using Core.Domain;
using Core.IRepository;
using Core.IServices;
using Core.Queries;
using Library.Cache;
using Library.Helpers;
using Library.Logging;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using Core.Mappers;
using Core.Aspects;
using Core.Messages;
using Core.IRepository.Admin;

namespace Services
{
    [CacheName("Culture")]
    public class ReadCultureService : BaseService, IReadCultureService
    {
        private const string CULTURE_SETTINGS = "Cultures";

        private readonly IAdminRepository<byte, Culture> repository;
        private readonly IAdminUnitOfWork unitOfWork;        

        public ReadCultureService(IAdminUnitOfWork unitOfWork, IAdminRepository<byte, Culture> repository)
        {
            this.repository = repository;
            this.unitOfWork = unitOfWork;                        
        }

        [Cache(Name = CULTURE_SETTINGS, NoExpiration = true)]
        public IEnumerable<CultureDto> GetAll()
        {
            return repository.FindAll().Map<Culture, CultureDto>();
        }

        public void InitStaticCache()
        {
            GetAll();
        }

        [DeleteCache(Name = CULTURE_SETTINGS)]
        public Response ResetStaticCache()
        {
            return Run(() =>
            {
                InitStaticCache();
            });
        }
    }
}